package my.hnb.android.controller;

import android.support.v4.app.FragmentManager;
import my.hnb.android.common.ActionEvent;
import my.hnb.android.common.ModelEvent;
import my.hnb.android.constant.ErrorConstants;

public abstract class AbstractController {
	// trace log xuong server
	//public LogMsg log;
	abstract public void handleViewEvent(ActionEvent e);
    abstract public void handleModelEvent(ModelEvent modelEvent);
    abstract public void handleSwitchActivity(ActionEvent e);
    abstract public void handleSwitchFragment(ActionEvent e) ;
    
    public void handleErrorModelEvent(final ModelEvent modelEvent) {
	}
    
    public void handleCommonError(ModelEvent modelEvent){    	
    	ActionEvent actionEvent = modelEvent.getActionEvent();
    	switch(modelEvent.getModelCode()){
    	case ErrorConstants.ERROR_SESSION_RESET:
    		actionEvent.controller = this;
    		break;
    	}
    }

	/**
	 * remove all fragment in back stack Muc dich: cac trang o menu chinh khong
	 * can luu trong stack khi chuyen cac trang trong menu.
	 * @author: BangHn
	 * @param fm
	 * @return: void
	 * @throws:
	 */
	public void removeAllInBackStack(FragmentManager fm) {
		for (int i = 0; i < fm.getBackStackEntryCount(); i++) {
			fm.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
		}
	}
}
